<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport"
	content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<meta content="yes" name="apple-mobile-web-app-capable">
<meta content="black" name="apple-mobile-web-app-status-bar-style">
<meta content="telephone=no" name="format-detection">
<title>购物车</title>
<link rel="stylesheet" type="text/css"
	href="${base}/templates/${config.theme}/mobile/static/css/layout.min.css" />
<link rel="stylesheet" type="text/css"
	href="${base}/templates/${config.theme}/mobile/static/css/common.min.css" />
<script type="text/javascript"
	src="${base}/templates/${config.theme}/mobile/static/js/jquery.js"></script>
<script type="text/javascript"
	src="${base}/templates/${config.theme}/mobile/static/js/jquery.cookie.js"></script>
<script type="text/javascript"
	src="${base}/templates/${config.theme}/mobile/static/js/ajax.js"></script>
</head>
<body>
	<header id="header" class="header">
		<div class="head_left fl">
			<a href="javascript:history.back(-1);"><span class="h_back"></span></a>
		</div>
		<span class="headtit">发起摇奖</span>
		<div class="head_right fr">
			<a href="${base}/"><span class="h_home"></span></a>
		</div>
	</header>
	<div style="line-height:44px; height:44px; width:100%"></div>
	<div id="cart_list">
		[#if magicWaitings.rows?? && magicWaitings.rows?size>0]
		<div class="space10"></div>
		<h2 class="order_sendby clearfix">
			<span>共${rows.total}件商品</span><span><font style="color: red"></font></span>
		</h2>

		<div class="cartdiv">

			[#list magicWaitings.rows as cartItem]
			<div class="cartlist clearfix">
				<div class="space10"></div>
				<div class="cartlistinner clearfix">
					<a href="${base}/magic/participationMagic?id=${cartItem.id}" class="cart_orderlist_i">
						<img salt="${cartItem.product.name}"
						src="${base}/static/img/zhuanpan.png" width="100" height="101">
					</a>
					<div class="cart_orderlist_info" style="margin:0 100px">
						<a href="goods.php?id=632">
							<p class="cart_g_name">${cartItem.unitPrice}元一注</p>
							<p class="cart_b_name"></p>
							<p class="fontred">${cartItem.unitPrice}元</p>
							<p class="space5"></p>
						</a>
						<div class="space5"></div>
						<div class="goods_Cnum clearfix" id="goods_Cnum">
							<div class="good_data_num J_pro_num_btn_cart">
								<span
									class="good_data_num_l J_num_cart_reduce good_data_num_l_act"
									onclick="changeQuantity(${cartItem.productId},'-')"> <a
									href="javascript:;">-</a>
								</span> <em class="good_data_num_m J_num_cart_txt"><input
									type="text" id="cartItem_quantity_${cartItem.productId}"
									value="${cartItem.quantity}" data="${cartItem.quantity}"
									size="3" style="border: 0px;"
									onBlur="changePrice(${cartItem.productId})" /></em> <span
									class="good_data_num_r J_num_cart_add"
									onclick="changeQuantity(${cartItem.productId},'+')"> <a
									href="javascript:;">+</a>
								</span>
							</div>
						</div>
					</div>
					<a class="cart_orderlist_p" style="display:block"> <span
						class="c_price" id="cartItem_subtotal_${cartItem.productId}">
							￥${cartItem.subtotal}</span>
					</a> <span class="delete"> <a
						href="javascript:if (confirm('您确实要把该商品移出购物车吗？')) deleteCartItem(${cartItem.id},'redirect');">
							删除 </a>
					</span>
					<div class="cart_orderlist" style="display:block">
					 [#list cartItem.fields as magicField] <span><input
						type="checkbox" name="item" value="${magicField.magic_id}"><label>${magicField.praisename}</label></span>
					[/#list]
					</div>
				</div>

			</div>
			<div class="cartlist clearfix"></div>
			[/#list]

			<div class="orderaction clearfix">
				<div class="fl"></div>
				<span id="order-integral"></span><br> <span
					style="color: red;text-align: center"></span><br>
				<p class="fr">
					<span class="c_t_price" id="totalPrice">￥${magicWaitings.totalPrice}</span>
				</p>
				<div class="clear"></div>
			</div>
		</div>


		<div class="bottomdiv clearfix">
			<div class="inner clearfix">
				<div class="fl">
					<a href="${base}/" class="btn_cancel" style="margin-top:0px;">继续购物</a>
				</div>
				<a [#if magicWaitings.cartItems?? && magicWaitings.cartItems?size>0]
					href="${base}/magic/add" [/#if] class="fr btn_sure"> 结 算 </a>
			</div>
		</div>
		[#else]
		<div class="nullicon">
			<span class="n_cart"></span>
			<p>您的购物车空空如也</p>
			<a class="btn_red incart" href="${base}/">去首页逛逛</a>
		</div>
		[/#if]
	</div>
</body>
</html>
<script type="text/javascript">
	//数量增加减
	function changeQuantity(productId, operate) {
		var cartItemNum = $("#cartItem_quantity_" + productId);
		;
		if ("+" == operate) {
			cartItemNum.val(Number(cartItemNum.val()) + 1);
			cartItemNum.attr("data", Number(cartItemNum.val()) + 1)
		} else if ("-" == operate) {
			cartItemNum.val(Number(cartItemNum.val()) - 1);
			cartItemNum.attr("data", Number(Number(cartItemNum.val()) - 1));
		}
		updateChangeQuantity(productId, cartItemNum.val());
	}

	function changePrice(productId) {
		var cartItemNum = $("#cartItem_quantity_" + productId);
		var quantity = cartItemNum.val();
		var reg = /^\+?[1-9][0-9]*$/;//正整数 
		if (!reg.test(quantity)) {
			alert("请输入数字!")
			cartItemNum.val(cartItemNum.attr("data"));
			return;
		}
		updateChangeQuantity(productId, quantity);
	}

	//更新购物车数量
	function updateChangeQuantity(productId, quantity) {
		$.axse("/cart_item/update", {
			"productId" : productId,
			"quantity" : quantity,
			"type" : 2
		}, function(data) {
			$("#cartItem_subtotal_" + productId).html("￥" + data.subtotal);
			$("#totalPrice").html("￥" + data.totalPrice);
		}, function(data) {
		});
	}

	//删除购物项
	function deleteCartItem(cartItemId, type) {
		//ajax
		$.axse("/cart_item/delete", {
			"id" : cartItemId
		}, function(data) {
			if (type == "ajax") {
				loadCart();
			} else if (type = "redirect") {
				location.href = "/cart/list"
			}
		}, function(data) {
		});

	}
</script>